/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jim
 */
@Entity
@Table(name = "SONG")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Song.findAll", query = "SELECT s FROM Song s"),
    @NamedQuery(name = "Song.findByIdSong", query = "SELECT s FROM Song s WHERE s.idSong = :idSong"),
    @NamedQuery(name = "Song.findByTitle", query = "SELECT s FROM Song s WHERE s.title = :title"),
    @NamedQuery(name = "Song.findByDuration", query = "SELECT s FROM Song s WHERE s.duration = :duration"),
    @NamedQuery(name = "Song.findByTracknr", query = "SELECT s FROM Song s WHERE s.tracknr = :tracknr"),
    @NamedQuery(name = "Song.findByDiskNumber", query = "SELECT s FROM Song s WHERE s.diskNumber = :diskNumber")})
public class Song implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_SONG")
    private Integer idSong;
    @Basic(optional = false)
    @Column(name = "TITLE")
    private String title;
    @Basic(optional = false)
    @Column(name = "DURATION")
    private float duration;
    @Basic(optional = false)
    @Column(name = "TRACKNR")
    private int tracknr;
    @Basic(optional = false)
    @Column(name = "DISK_NUMBER")
    private int diskNumber;
    @ManyToMany(mappedBy = "songCollection")
    private Collection<Playlist> playlistCollection;
    @JoinColumn(name = "ID_ALBUM", referencedColumnName = "ID_ALBUM")
    @ManyToOne(optional = false)
    private Album idAlbum;

    public Song() {
    }

    public Song(Integer idSong) {
        this.idSong = idSong;
    }

    public Song(Integer idSong, String title, float duration, int tracknr, int diskNumber) {
        this.idSong = idSong;
        this.title = title;
        this.duration = duration;
        this.tracknr = tracknr;
        this.diskNumber = diskNumber;
    }

    //Επιπλέον δημιουργός για αποθήκευση στη βάση
    public Song(Integer idSong, String title, float duration, int tracknr, int diskNumber, Album idAlbum) {
        this.idSong = idSong;
        this.title = title;
        this.duration = duration;
        this.tracknr = tracknr;
        this.diskNumber = diskNumber;
        this.idAlbum= idAlbum;
    }

    public Integer getIdSong() {
        return idSong;
    }

    public void setIdSong(Integer idSong) {
        Integer oldIdSong = this.idSong;
        this.idSong = idSong;
        changeSupport.firePropertyChange("idSong", oldIdSong, idSong);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        String oldTitle = this.title;
        this.title = title;
        changeSupport.firePropertyChange("title", oldTitle, title);
    }

    public float getDuration() {
        return duration;
    }

    public void setDuration(float duration) {
        float oldDuration = this.duration;
        this.duration = duration;
        changeSupport.firePropertyChange("duration", oldDuration, duration);
    }

    public int getTracknr() {
        return tracknr;
    }

    public void setTracknr(int tracknr) {
        int oldTracknr = this.tracknr;
        this.tracknr = tracknr;
        changeSupport.firePropertyChange("tracknr", oldTracknr, tracknr);
    }

    public int getDiskNumber() {
        return diskNumber;
    }

    public void setDiskNumber(int diskNumber) {
        int oldDiskNumber = this.diskNumber;
        this.diskNumber = diskNumber;
        changeSupport.firePropertyChange("diskNumber", oldDiskNumber, diskNumber);
    }

    @XmlTransient
    public Collection<Playlist> getPlaylistCollection() {
        return playlistCollection;
    }

    public void setPlaylistCollection(Collection<Playlist> playlistCollection) {
        this.playlistCollection = playlistCollection;
    }

    public Album getIdAlbum() {
        return idAlbum;
    }

    public void setIdAlbum(Album idAlbum) {
        Album oldIdAlbum = this.idAlbum;
        this.idAlbum = idAlbum;
        changeSupport.firePropertyChange("idAlbum", oldIdAlbum, idAlbum);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idSong != null ? idSong.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Song)) {
            return false;
        }
        Song other = (Song) object;
        if ((this.idSong == null && other.idSong != null) || (this.idSong != null && !this.idSong.equals(other.idSong))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "POJOS.Song[ idSong=" + idSong + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
